#ifndef DTU_4G_H
#define DTU_4G_H

#include <QObject>
#include <QSerialPort>
#include <QSerialPortInfo>

/* 使用4GDTU模块连接阿里云云平台所需的信息 */
struct dtu_4G_aliyun_data
{
    QByteArray ProductKey;
    QByteArray DeviceName;
    QByteArray DeviceSecret;
    QByteArray territory;
    QByteArray Sub_Topic;
    QByteArray Pub_Topic;
    QByteArray CON;
};

class dtu_4G : public QObject
{
    Q_OBJECT
private:
    QSerialPort *serialPort = nullptr;  //串口对象
    QByteArray config_recv_buf;
    bool is_aly_serianet_connect = false;
    struct dtu_4G_aliyun_data aly_serianet_data{};
    bool dev_reset = false;     //设备进行重启标志

public:
    explicit dtu_4G(QObject *parent = nullptr);
    explicit dtu_4G(QString serialName,QObject *parent = nullptr);
    explicit dtu_4G(QSerialPort *serialPort);

    virtual ~dtu_4G();

public:
    int aliyun_serianet_connect(struct dtu_4G_aliyun_data &data);    //使用阿里云透传模式连接阿里云云平台设备
    int aliyun_disconnect();    //断开阿里云透传模式下与阿里云云平台设备的连接
    void aliyun_serianet_pub_mes(QByteArray &message);      //在阿里云透传模式下将数据上传到阿里云平台设备
    void aliyun_serianet_pub_mes(const char *cstr);

    bool getIs_aly_serianet_connect() const;
    void dtu_4g_reset(void);    //重置并重启4G模块

private slots:
    void serialPortReadyRead();
    void aly_serianet_connect_slots(qint8 state);
    void dev_reset_slots(qint8 state);

signals:
    void aly_serianet_connect_signal(qint8 state);
    void dev_reset_signal(qint8 state);
    void aly_serianet_connect_ok(void);
    void dev_reset_ok_signal(void);
    void aly_disconnect(void);

};

#endif // DTU_4G_H
